package goleetcode

import "duan.com/leetcode/utils"

func mergeNodes(head *utils.ListNode) *utils.ListNode {
	dummy := &utils.ListNode{}
	tail := dummy
	total := 0
	for cur := head.Next; cur != nil; cur = cur.Next {
		if cur.Val == 0 {
			node := &utils.ListNode{Val: total}
			tail.Next = node
			tail = tail.Next
			total = 0
		}
		total += cur.Val
	}
	return dummy.Next
}
